#include "mdmethods.h"
#include "ui_mdmethods.h"
//#include "def.h"
#include <QDebug>






MDmethods::MDmethods(QList<Method*> * lmt,QWidget *parent) :
    QDialog(parent),
    ui(new Ui::MDmethods)
{
    ui->setupUi(this);
    this->wlmt=lmt;
    connect(this->ui->btn_ok,SIGNAL(clicked()),SLOT(slot_ok()));
    connect(this->ui->lw_met,SIGNAL(currentRowChanged(int)),SLOT(slot_lwselect(int)));
    for(int i = 0 ; i < wlmt->size() ; i++){
        QListWidgetItem * it = new QListWidgetItem(wlmt->at(i)->name);
        this->ui->lw_met->addItem(it);
    }
}

MDmethods::~MDmethods()
{
    //clear it

    delete ui;

}

void MDmethods::changeEvent(QEvent *e)
{
    QDialog::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}

void MDmethods::slot_ok(){
    this->accept();
}

void MDmethods::slot_lwselect(int a){
    for(int i = this->ui->lw_params->count(); i > 0 ; i --){
        QListWidgetItem * it = this->ui->lw_params->item(i);
        //this->ui->lw_params->removeItemWidget(it);
        delete it;
    }
    this->ui->lw_params->clear();
    QListWidgetItem * it = new QListWidgetItem(tr("Authors: ")+this->wlmt->at(a)->authors);
    this->ui->lw_params->addItem(it);

    it = new QListWidgetItem(tr("Describe: ")+this->wlmt->at(a)->desc);
    this->ui->lw_params->addItem(it);

    it = new QListWidgetItem(tr("Exec: ")+this->wlmt->at(a)->exec);
    this->ui->lw_params->addItem(it);

    it = new QListWidgetItem(tr("Return type: ")+this->wlmt->at(a)->mtype);
    this->ui->lw_params->addItem(it);

    qDebug()<<this->ui->lw_params->count();


    for(int i = 0 ; i < this->wlmt->at(a)->params.size(); i++){
        qDebug()<<"data from mm"<<this->wlmt->at(a)->params.at(i);
        it = new QListWidgetItem(tr("Parameter ")+QString::number(i+1)+" : "+
                                 this->wlmt->at(a)->params.at(i));
        this->ui->lw_params->addItem(it);

    }

}
